package com.leyou.user.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.security.SecureRandom;
@Data
@Configuration//配置类
@ConfigurationProperties(prefix ="ly.encoder.crypt" )//读取配置文件的内容，prefix前缀
public class passwordConfig {
    /*
    * 密码加密的参数：
    * 1.加密的强度
    * 2.随机的salt盐
    *
    * */

    private int strength;//加密的强度
    private String secret;//加密的salt盐，采用随机的盐

    @Bean
    public BCryptPasswordEncoder encoder(){
        // SecureRandom 利用密钥生成随机安全码  import java.security.SecureRandom;
        SecureRandom secureRandom=new SecureRandom(secret.getBytes());

        return new BCryptPasswordEncoder(strength,secureRandom);
    }

}
